package com.linktel.productionLine.controller;

import com.linktel.productionLine.common.BaseResponse;
import com.linktel.productionLine.common.ErrorCode;
import com.linktel.productionLine.common.ResultUtils;
import com.linktel.productionLine.entity.dto.baseStep.BaseStepDTO;
import com.linktel.productionLine.entity.query.baseStep.ListBaseStepByMonthlyPlanningQuery;
import com.linktel.productionLine.exception.BusinessException;
import com.linktel.productionLine.service.BaseStepService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 对工序base_step的有关请求
 *
 * @Author HuangJiaHui
 * @Date 2023/8/25 10:18
 */
@RestController
@RequestMapping("/baseStep")
@AllArgsConstructor
public class BaseStepController {

    protected BaseStepService baseStepService;

    /**
     * 查询所有工序
     * @return 工序列表
     */
    @GetMapping
    public BaseResponse<List<BaseStepDTO>> listBaseStep() {
        List<BaseStepDTO> baseStepDTOList = baseStepService.listBaseStep();
        return ResultUtils.success(baseStepDTOList);
    }

    /**
     * 查询已在月度规划产能信息中定义的关键工序
     * @return 工序列表
     */
    @GetMapping("/monthlyPlanning")
    public BaseResponse<List<BaseStepDTO>> listBaseStepByMonthlyPlanning(ListBaseStepByMonthlyPlanningQuery listBaseStepByMonthlyPlanningQuery) {
        if (listBaseStepByMonthlyPlanningQuery == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        List<BaseStepDTO> baseStepDTOList = baseStepService.listBaseStepByMonthlyPlanning(listBaseStepByMonthlyPlanningQuery);
        return ResultUtils.success(baseStepDTOList);
    }
}
